package com.tanhua.config.template;

import com.baidu.aip.face.AipFace;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;

public class AipTemplate {
    @Autowired
    private AipFace client;

    public boolean detect(String imageUrl) {
        String imageType = "URL";
        // 人脸检测
        HashMap<String, String> options = new HashMap<>();
        options.put("face_field", "age");
        options.put("max_face_num", "2");
        options.put("face_type", "LIVE");
        options.put("liveness_control", "NONE");

        JSONObject res = client.detect(imageUrl, imageType, options);
        System.out.println(res.toString(2));

        System.out.println(res.get("error_code"));
        return "0".equals(res.get("error_code").toString());
    }
}
